package edu.luas.digitalmedia.controller;

import edu.luas.digitalmedia.service.MyAddressService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/address/delete")
public class MyAddressDeleteController  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("html/text;charset=utf-8");
        Integer id = Integer.parseInt(req.getParameter("id"));
        int count = new MyAddressService().delete(id);
        if(count>0){
            req.getRequestDispatcher("/address/list").forward(req,resp);

        }else{
            resp.getWriter().print("删除失败");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
